package cn.itcast.mybatis.demo3;

import static org.junit.Assert.*;

import java.io.IOException;
import java.util.List;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import cn.itcast.mybatis.demo3.impl.UserDaoImpl;
import cn.itcast.mybatis.pojo.User;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(value="classpath:applicationContext3.xml")
public class UserDaoTest {

	@Autowired
	private UserDao dao;
	
	

	/**
	 * 通过id来查询用户
	 */
	@Test
	public void getUserById() {
		User user = dao.getUserById(16);
		System.out.println(user.toString());
	}

	
	/**
	 * 通过地址来进行模糊查询
	 */
	
	@Test
	public void getUserByAddress() throws Exception {
		UserDao dao = new UserDaoImpl();
		List<User> userList = dao.getUserByAddress("河南");
		for (User user : userList) {
			System.out.println(user.toString());
		}
	}
	
	@Test
	public void deleteUser() throws Exception {
		UserDao dao = new UserDaoImpl();
		dao.deleteUser(29);
	}
	
	
	
	
	
	
	
}
